package com.kk.lesson02;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class TestActionEvent02 {
    public static void main(String[] args) {
       //俩个按钮，实现同一监听
        //开始 停止
        Frame frame = new Frame();
        Button start = new Button("start");
        Button stop = new Button("stop");

        MyMonitor myMonitor = new MyMonitor();
        //可以显示的定义触发返回的命令，如果不显示定义，则会走默认的值
        //可以多个按钮只写一个监听类
        stop.setActionCommand("stop1");

        start.addActionListener(myMonitor);
        stop.addActionListener(myMonitor);
        frame.add(start,BorderLayout.NORTH);
        frame.add(stop,BorderLayout.SOUTH);
        frame.pack();
        frame.setVisible(true);

    }

}
class MyMonitor implements ActionListener{

    @Override
    public void actionPerformed(ActionEvent e) {
        //e.getActionCommand()获取按钮的一些信息
        System.out.println("按钮被点击了：msg"+e.getActionCommand());
    }
}


